<template>
  <div class="servegroup">
    <ConTitle :info="info"></ConTitle>
    <el-table class="measuretable" :data="testList" stripe style="width: 100%">
      <el-table-column prop="id" label="序号" type="index"> </el-table-column>
      <el-table-column prop="id" label="测量id" width="250"> </el-table-column>
      <el-table-column prop="name" label="测量名称"> </el-table-column>
      <el-table-column prop="unit" label="测量单位"> </el-table-column>
      <el-table-column prop="cTime" label="创建时间">
        <template slot-scope="scope">
          {{ scope.row.cTime | cTimeType }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            @click="editFun(scope.row)"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="delFun(scope.row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import ConTitle from "@/components/ConTitle.vue";
import moment from "moment";
import { $testDel, $testList } from "@/api/index";

export default {
  name: "TestList",
  data() {
    return {
      info: {
        path: "自定义类型/",
        text: "测量类型",
        msg: "-展示所有自定义的测量类型，提供了添加测量类型、修改测量类型、删除测量类型等功能。",
      },
      testList: [],
    };
  },
  components: {
    ConTitle,
  },
  filters: {
    cTimeType(value) {
      return moment(value).format("LL");
    },
  },
  mounted() {
    this.getListData();
  },
  methods: {
    getListData() {
      $testList().then((res) => {
        console.log(res);
        this.testList = res.data.data;
      });
    },
    editFun(row) {
      // 页面跳转并传参
      this.$router.push({ path: "/test/testtype", query: row });
    },
    delFun(row) {
      console.log(row);
      this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          $testDel({ id: row.id }).then((res) => {
            if (res.data.msg == "success") {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getListData();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.sp1 {
  font-weight: 900;
}
.sp {
  margin-left: 80px;
}
.box-card {
  margin-top: 10px;
}
.text {
  margin-top: 20px;
}
.inputt {
  margin-left: 50px;
  width: 300px;
}
.inputt1 {
  margin-left: 75px;
  width: 300px;
}
.beizhu {
  margin-top: 10px;
}
</style>